package com.example.wochacha.mvpdemo.login.sample;

import com.example.wochacha.mvpdemo.login.LoginComponent;
import com.example.wochacha.mvpdemo.login.LoginModule;
import com.example.wochacha.mvpdemo.login.LoginModule_ProvideLoginPresenterFactory;
import com.example.wochacha.mvpdemo.login.LoginModule_ProvideLoginViewFactory;
import com.example.wochacha.mvpdemo.login.presenter.ILoginPresenter;
import com.example.wochacha.mvpdemo.login.view.ILoginView;
import com.example.wochacha.mvpdemo.login.view.LoginActivity;
import com.example.wochacha.mvpdemo.login.view.LoginActivity_MembersInjector;

import javax.annotation.Generated;
import javax.inject.Provider;

import dagger.MembersInjector;
import dagger.internal.Preconditions;

@Generated(
  value = "dagger.internal.codegen.ComponentProcessor",
  comments = "https://google.github.io/dagger"
)
/**
 * 主要用于初始化实，没有真正进行依赖之间的关联
 */
public final class DaggerLoginComponent implements LoginComponent {
  // Provider就是所提供的依赖
  private Provider<ILoginView> provideLoginViewProvider;

  private Provider<ILoginPresenter> provideLoginPresenterProvider;

  private MembersInjector<LoginActivity> loginActivityMembersInjector;

  private DaggerLoginComponent(Builder builder) {
    assert builder != null;
    initialize(builder);
  }

  public static Builder builder() {
    return new Builder();
  }

  /**
   * 这个方法中，调用LoginModule所生成类的create方法，用于创建生成类的对象，其实就是Provider对象
   * 这个Provider就是LoginPresenterCompl_Factory的get方法中，provider.get所用到的provider
   * @param builder
   */
  private void initialize(final Builder builder) {

    this.provideLoginViewProvider = LoginModule_ProvideLoginViewFactory.create(builder.loginModule);

    this.provideLoginPresenterProvider =
        LoginModule_ProvideLoginPresenterFactory.create(
            builder.loginModule, provideLoginViewProvider);

    // 将provideLoginViewProvider传递LoginActivity_MembersInjector中进行实例化
    // 这个是LoginActivity开头的类，它其实就是LoginActivity对应的注入类
    this.loginActivityMembersInjector =
        LoginActivity_MembersInjector.create(provideLoginPresenterProvider);
  }

  /**
   * 这里调用类LoginActivityMembersInjector的injectMembers(activity)，将LoginActivity注入到该类中
   * @param activity
   */
  @Override
  public void inject(LoginActivity activity) {
    loginActivityMembersInjector.injectMembers(activity);
  }

  /**
   * 用于创建Module和自身实例
   */
  public static final class Builder {
    private LoginModule loginModule;

    private Builder() {}

    public LoginComponent build() {
      if (loginModule == null) {
        throw new IllegalStateException(LoginModule.class.getCanonicalName() + " must be set");
      }
      return new DaggerLoginComponent(this);
    }

    public Builder loginModule(LoginModule loginModule) {
      this.loginModule = Preconditions.checkNotNull(loginModule);
      return this;
    }
  }
}
